package internal

import (
	"MoSkeleton/framework"
	"MoSkeleton/framework/core/config/properties_gin"
	"MoSkeleton/framework/core/consts"
	"MoSkeleton/framework/mo_gin/middleware/authentication"
	"MoSkeleton/framework/mo_gin/middleware/authorization"
	au "MoSkeleton/web/middleware/authorize"
	"MoSkeleton/web/middleware/captcha_mw"
	"MoSkeleton/web/middleware/loginfo"
	"MoSkeleton/web/v1/http"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

type RouterMakeup struct {
	authSubject authorization.AuthSubject
}

var authorizeGroupHandlers = []gin.HandlerFunc{authentication.DoAuthGroup(), au.DoCheckBlackToken()}

func (r *RouterMakeup) Make(ginProperty properties_gin.GinProperty) error {
	r.authSubject = NewAuthSubject()
	contextPathGroup := r.makeContextPathGroup(ginProperty)
	r.makeStatic(contextPathGroup, ginProperty)
	r.makeOtherRouter(contextPathGroup, ginProperty)
	r.makePublicPathGroup(contextPathGroup, ginProperty)
	r.makeSystemPathGroup(contextPathGroup, ginProperty)
	r.makeCommonPathGroup(contextPathGroup, ginProperty)
	r.makeMonitorPathGroup(contextPathGroup, ginProperty)
	return nil
}

func (r *RouterMakeup) makeContextPathGroup(ginProperty properties_gin.GinProperty) *gin.RouterGroup {
	contextPath := ginProperty.Router.ContextPath
	if contextPath != "" {
		contextPathGroup := framework.GinRouter.Group(contextPath)
		return contextPathGroup
	}
	return nil
}

func (r *RouterMakeup) makeSystemPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysPathGroup := r.createRouterGroup(ginProperty.Router.SystemGroupPath, "/system", contextPathGroup, authorizeGroupHandlers...)
	sysPathGroup.POST("/logout", http.MainCtrlGroupInst.SystemCtrlGroupInst.SysAuthCtrlInst.Logout)
	//user
	r.makeSystemUserPathGroup(sysPathGroup, ginProperty)
	//menu
	r.makeSystemMenuPathGroup(sysPathGroup, ginProperty)
	//dict
	r.makeSystemDictPathGroup(sysPathGroup, ginProperty)
	//config
	r.makeSystemConfigPathGroup(sysPathGroup, ginProperty)
	//post
	r.makeSystemPostPathGroup(sysPathGroup, ginProperty)
	//dept
	r.makeSystemDeptPathGroup(sysPathGroup, ginProperty)
	//role
	r.makeSystemRolePathGroup(sysPathGroup, ginProperty)
	//notice
	r.makeSystemNoticePathGroup(sysPathGroup, ginProperty)
}
func (r *RouterMakeup) makeCommonPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	commonPathGroup := r.createRouterGroup("", "/common", contextPathGroup)
	commonPathGroup.POST("/upload", http.MainCtrlGroupInst.CommonCtrlGroupInst.CommonCtrlInst.UploadFile)
}

func (r *RouterMakeup) makePublicPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	whitePathGroup := r.createRouterGroup(ginProperty.Router.PublicGroupPath, "/public", contextPathGroup)

	whitePathGroup.GET("/captchaImage", http.MainCtrlGroupInst.PublicCtrlGroupInst.CaptchaCtlInst.Captcha)
	whitePathGroup.POST("/login", loginfo.DoLogLoginInfo(), captcha_mw.DoCheckCaptcha(), http.MainCtrlGroupInst.PublicCtrlGroupInst.AuthCtrlInst.Login)
}

func (r *RouterMakeup) makeMonitorPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	monitorPathGroup := r.createRouterGroup("/monitor", "/monitor", contextPathGroup, authorizeGroupHandlers...)
	r.makeMonitorOperLogPathGroup(monitorPathGroup, ginProperty)
	r.makeMonitorLoginInfoPathGroup(monitorPathGroup, ginProperty)
}

// user
func (r *RouterMakeup) makeSystemUserPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysUserCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysUserCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysUserCtrlInst.InitCtrl()}
	userPathGroup := r.createRouterGroup("/user", "/user", contextPathGroup)
	userPathGroup.GET("/getInfo", sysUserCtrlInst.GetLoginUserInfo)
	userPathGroup.GET("/:id", authorization.CheckPermission("system:user:query", r.authSubject), sysUserCtrlInst.GetUserDetailById)
	userPathGroup.GET("/", authorization.CheckPermission("system:user:query", r.authSubject), sysUserCtrlInst.GetUserDetailById)
	userPathGroup.GET("/list", authorization.CheckPermission("system:user:list", r.authSubject), sysUserCtrlInst.GetUserPage)
	userPathGroup.GET("/deptTree", authorization.CheckPermission("system:user:list", r.authSubject), sysUserCtrlInst.GetDeptTree)

	userPathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:add", r.authSubject), sysUserCtrlInst.AddUser)...)
	userPathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:edit", r.authSubject), sysUserCtrlInst.UpdateUser)...)
	userPathGroup.PUT("/changeStatus", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:edit", r.authSubject), sysUserCtrlInst.ChangeStatus)...)
	userPathGroup.PUT("/resetPwd", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:resetPwd", r.authSubject), sysUserCtrlInst.ResetPassword)...)
	userPathGroup.DELETE("/:ids", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:remove", r.authSubject), sysUserCtrlInst.DeleteUser)...)
	userPathGroup.POST("/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:export", r.authSubject), sysUserCtrlInst.ExportUser)...)
	userPathGroup.POST("/importTemplate", r.mergeHandlers(extraHandlers, sysUserCtrlInst.ImportTemplate)...)
	userPathGroup.POST("/importData", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:import", r.authSubject), sysUserCtrlInst.ImportUser)...)
	userPathGroup.GET("/authRole/:id", authorization.CheckPermission("system:user:query", r.authSubject), sysUserCtrlInst.GetAuthRole)
	userPathGroup.PUT("/authRole", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:user:edit", r.authSubject), sysUserCtrlInst.UpdateAuthRole)...)
	userPathGroup.GET("/profile", sysUserCtrlInst.GetProfile)
	userPathGroup.PUT("/profile", r.mergeHandlers(extraHandlers, sysUserCtrlInst.UpdateProfile)...)
	userPathGroup.PUT("/profile/updatePwd", r.mergeHandlers(extraHandlers, sysUserCtrlInst.UpdateProfilePassword)...)
	userPathGroup.POST("/profile/avatar", r.mergeHandlers(extraHandlers, sysUserCtrlInst.UpdateProfileAvatar)...)
}

// menu
func (r *RouterMakeup) makeSystemMenuPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysMenuCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysMenuCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysMenuCtrlInst.InitCtrl()}
	menuPathGroup := r.createRouterGroup("/menu", "/menu", contextPathGroup)
	menuPathGroup.GET("/getRouters", sysMenuCtrlInst.GetRouters)
	menuPathGroup.GET("/list", authorization.CheckPermission("system:menu:list", r.authSubject), sysMenuCtrlInst.GetMenuAll)
	menuPathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:menu:add", r.authSubject), sysMenuCtrlInst.AddMenu)...)
	menuPathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:menu:edit", r.authSubject), sysMenuCtrlInst.UpdateMenuById)...)
	menuPathGroup.GET("/:id", authorization.CheckPermission("system:menu:query", r.authSubject), sysMenuCtrlInst.GetMenuById)
	menuPathGroup.DELETE("/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:menu:remove", r.authSubject), sysMenuCtrlInst.DeleteById)...)
	menuPathGroup.GET("/treeselect", sysMenuCtrlInst.Treeselect)
	menuPathGroup.GET("/roleMenuTreeselect/:roleId", sysMenuCtrlInst.RoleMenuTreeselect)
}

// dict
func (r *RouterMakeup) makeSystemDictPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	dictTypeCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysDictTypeCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), dictTypeCtrlInst.InitCtrl()}
	dictPathGroup := r.createRouterGroup("/dict", "/dict", contextPathGroup)
	//type
	dictPathGroup.GET("/type/list", authorization.CheckPermission("system:dict:list", r.authSubject), dictTypeCtrlInst.GetDataTypeList)
	dictPathGroup.GET("/type/:id", authorization.CheckPermission("system:dict:query", r.authSubject), dictTypeCtrlInst.GetDataTypeById)
	dictPathGroup.GET("/type/optionselect", dictTypeCtrlInst.OptionSelect)
	dictPathGroup.PUT("/type", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:edit", r.authSubject), dictTypeCtrlInst.UpdateDataTypeById)...)
	dictPathGroup.POST("/type", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:add", r.authSubject), dictTypeCtrlInst.AddDataType)...)
	dictPathGroup.DELETE("/type/refreshCache", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:remove", r.authSubject), dictTypeCtrlInst.RefreshCache)...)
	dictPathGroup.DELETE("/type/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:remove", r.authSubject), dictTypeCtrlInst.DeleteDataTypeById)...)
	dictPathGroup.POST("/type/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:export", r.authSubject), dictTypeCtrlInst.ExportDataType)...)

	//data
	dictDataCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysDictDataCtrlInst
	extraHandlers = []gin.HandlerFunc{loginfo.DoLogOperInfo(), dictDataCtrlInst.InitCtrl()}
	dictPathGroup.GET("/data/type/:dictType", dictDataCtrlInst.GetDataListByDictType)
	dictPathGroup.GET("/data/list", authorization.CheckPermission("system:dict:list", r.authSubject), dictDataCtrlInst.GetDictDataPage)
	dictPathGroup.GET("/data/:id", authorization.CheckPermission("system:dict:query", r.authSubject), dictDataCtrlInst.GetDictDataById)
	dictPathGroup.POST("/data", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:add", r.authSubject), dictDataCtrlInst.AddDictData)...)
	dictPathGroup.PUT("/data", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:edit", r.authSubject), dictDataCtrlInst.UpdateDictDataById)...)
	dictPathGroup.DELETE("/data/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:remove", r.authSubject), dictDataCtrlInst.DeleteById)...)
	dictPathGroup.POST("/data/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dict:export", r.authSubject), dictDataCtrlInst.ExportDictData)...)
}

// config
func (r *RouterMakeup) makeSystemConfigPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysConfigCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysConfigCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysConfigCtrlInst.InitCtrl()}
	configPathGroup := r.createRouterGroup("/config", "/config", contextPathGroup)
	configPathGroup.GET("/list", authorization.CheckPermission("system:config:list", r.authSubject), sysConfigCtrlInst.GetConfigPage)
	configPathGroup.GET("/:id", authorization.CheckPermission("system:config:query", r.authSubject), sysConfigCtrlInst.GetConfigById)
	configPathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:config:add", r.authSubject), sysConfigCtrlInst.AddConfig)...)
	configPathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:config:edit", r.authSubject), sysConfigCtrlInst.UpdateConfigById)...)
	configPathGroup.DELETE("/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:config:remove", r.authSubject), sysConfigCtrlInst.DeleteById)...)
	configPathGroup.DELETE("/refreshCache", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:config:remove", r.authSubject), sysConfigCtrlInst.RefreshCache)...)
	configPathGroup.GET("/configKey/:configKey", sysConfigCtrlInst.GetByConfigKey)
	configPathGroup.POST("/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:config:export", r.authSubject), sysConfigCtrlInst.ExportConfig)...)
}

// post
func (r *RouterMakeup) makeSystemPostPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysPostCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysPostCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysPostCtrlInst.InitCtrl()}
	postPathGroup := r.createRouterGroup("/post", "/post", contextPathGroup)
	postPathGroup.GET("/list", authorization.CheckPermission("system:post:list", r.authSubject), sysPostCtrlInst.GetPostPage)
	postPathGroup.GET("/:id", authorization.CheckPermission("system:post:query", r.authSubject), sysPostCtrlInst.GetPostById)
	postPathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:post:add", r.authSubject), sysPostCtrlInst.AddPost)...)
	postPathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:post:edit", r.authSubject), sysPostCtrlInst.UpdatePostById)...)
	postPathGroup.DELETE("/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:post:remove", r.authSubject), sysPostCtrlInst.DeletePostById)...)
	postPathGroup.POST("/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:post:export", r.authSubject), sysPostCtrlInst.ExportPost)...)
}

// dept
func (r *RouterMakeup) makeSystemDeptPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysDeptCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysDeptCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysDeptCtrlInst.InitCtrl()}
	deptPathGroup := r.createRouterGroup("/dept", "/dept", contextPathGroup)
	deptPathGroup.GET("/list", authorization.CheckPermission("system:dept:list", r.authSubject), sysDeptCtrlInst.GetDeptAll)
	deptPathGroup.GET("/:id", authorization.CheckPermission("system:dept:query", r.authSubject), sysDeptCtrlInst.GetDeptById)
	deptPathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dept:add", r.authSubject), sysDeptCtrlInst.AddDept)...)
	deptPathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dept:edit", r.authSubject), sysDeptCtrlInst.UpdateDeptById)...)
	deptPathGroup.DELETE("/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:dept:remove", r.authSubject), sysDeptCtrlInst.DeleteById)...)
	deptPathGroup.GET("/list/exclude/:id", authorization.CheckPermission("system:dept:list", r.authSubject), sysDeptCtrlInst.GetExcludeDeptAndChildren)
}

// role
func (r *RouterMakeup) makeSystemRolePathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysRoleCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysRoleCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysRoleCtrlInst.InitCtrl()}
	rolePathGroup := r.createRouterGroup("/role", "/role", contextPathGroup)
	rolePathGroup.GET("/list", authorization.CheckPermission("system:role:list", r.authSubject), sysRoleCtrlInst.GetRolePage)
	rolePathGroup.GET("/:id", authorization.CheckPermission("system:role:query", r.authSubject), sysRoleCtrlInst.GetRoleById)
	rolePathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:add", r.authSubject), sysRoleCtrlInst.AddRole)...)
	rolePathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:edit", r.authSubject), sysRoleCtrlInst.UpdateRoleById)...)
	rolePathGroup.PUT("/changeStatus", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:edit", r.authSubject), sysRoleCtrlInst.UpdateRoleStatus)...)
	rolePathGroup.DELETE("/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:remove", r.authSubject), sysRoleCtrlInst.DeleteById)...)
	rolePathGroup.GET("/deptTree/:id", authorization.CheckPermission("system:role:query", r.authSubject), sysRoleCtrlInst.GetDeptTreeByRole)
	rolePathGroup.PUT("/dataScope", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:edit", r.authSubject), sysRoleCtrlInst.UpdateDataScope)...)
	rolePathGroup.POST("/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:export", r.authSubject), sysRoleCtrlInst.ExportRole)...)
	//authUser
	roleAuthUserCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.RoleAuthUserCtrlInst
	extraHandlers = []gin.HandlerFunc{loginfo.DoLogOperInfo(), roleAuthUserCtrlInst.InitCtrl()}
	authUserPathGroup := r.createRouterGroup("/authUser", "/authUser", rolePathGroup)
	authUserPathGroup.GET("/allocatedList", authorization.CheckPermission("system:role:list", r.authSubject), roleAuthUserCtrlInst.GetAllocatedListPage)
	authUserPathGroup.GET("/unallocatedList", authorization.CheckPermission("system:role:list", r.authSubject), roleAuthUserCtrlInst.GetUnallocatedListPage)
	authUserPathGroup.PUT("/selectAll", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:edit", r.authSubject), roleAuthUserCtrlInst.AuthUserAll)...)
	authUserPathGroup.PUT("/cancel", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:edit", r.authSubject), roleAuthUserCtrlInst.CancelAuthUser)...)
	authUserPathGroup.PUT("/cancelAll", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:role:edit", r.authSubject), roleAuthUserCtrlInst.CancelAuthUserAll)...)
}

// notice
func (r *RouterMakeup) makeSystemNoticePathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysNoticeCtrlInst := http.MainCtrlGroupInst.SystemCtrlGroupInst.SysNoticeCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysNoticeCtrlInst.InitCtrl()}
	noticePathGroup := r.createRouterGroup("/notice", "/notice", contextPathGroup)
	noticePathGroup.GET("/list", authorization.CheckPermission("system:notice:list", r.authSubject), sysNoticeCtrlInst.GetNoticePage)
	noticePathGroup.GET("/:id", authorization.CheckPermission("system:notice:query", r.authSubject), sysNoticeCtrlInst.GetNoticeById)
	noticePathGroup.POST("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:notice:add", r.authSubject), sysNoticeCtrlInst.AddNotice)...)
	noticePathGroup.PUT("", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:notice:edit", r.authSubject), sysNoticeCtrlInst.UpdateNotice)...)
	noticePathGroup.DELETE("/:id", r.mergeHandlers(extraHandlers, authorization.CheckPermission("system:notice:remove", r.authSubject), sysNoticeCtrlInst.DeleteNotices)...)
}

// monitor
// oper log
func (r *RouterMakeup) makeMonitorOperLogPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysOperLogCtrlInst := http.MainCtrlGroupInst.MonitorCtrlGroupInst.SysOperLogCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysOperLogCtrlInst.InitCtrl()}
	operLogPathGroup := r.createRouterGroup("/operlog", "/operlog", contextPathGroup)
	operLogPathGroup.GET("/list", authorization.CheckPermission("monitor:operlog:list", r.authSubject), sysOperLogCtrlInst.GetOperLogPage)
	operLogPathGroup.DELETE("/:ids", r.mergeHandlers(extraHandlers, authorization.CheckPermission("monitor:operlog:remove", r.authSubject), sysOperLogCtrlInst.DeleteOperLogs)...)
	operLogPathGroup.DELETE("/clean", r.mergeHandlers(extraHandlers, authorization.CheckPermission("monitor:operlog:remove", r.authSubject), sysOperLogCtrlInst.CleanTable)...)
	operLogPathGroup.POST("/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("monitor:operlog:export", r.authSubject), sysOperLogCtrlInst.ExportOperLogs)...)
}

// login log info
func (r *RouterMakeup) makeMonitorLoginInfoPathGroup(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	sysLoginInfoCtrlInst := http.MainCtrlGroupInst.MonitorCtrlGroupInst.SysLoginInfoCtrlInst
	extraHandlers := []gin.HandlerFunc{loginfo.DoLogOperInfo(), sysLoginInfoCtrlInst.InitCtrl()}
	loginLogPathGroup := r.createRouterGroup("/logininfor", "/logininfor", contextPathGroup)
	loginLogPathGroup.GET("/list", authorization.CheckPermission("monitor:logininfor:list", r.authSubject), sysLoginInfoCtrlInst.GetLoginInfoPage)
	loginLogPathGroup.DELETE("/:ids", r.mergeHandlers(extraHandlers, authorization.CheckPermission("monitor:logininfor:remove", r.authSubject), sysLoginInfoCtrlInst.DeleteLoginInfos)...)
	loginLogPathGroup.DELETE("/clean", r.mergeHandlers(extraHandlers, authorization.CheckPermission("monitor:logininfor:remove", r.authSubject), sysLoginInfoCtrlInst.CleanTable)...)
	loginLogPathGroup.POST("/export", r.mergeHandlers(extraHandlers, authorization.CheckPermission("monitor:logininfor:export", r.authSubject), sysLoginInfoCtrlInst.ExportLoginInfos)...)
}

func (r *RouterMakeup) makeStatic(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	for mapKey, mapValue := range ginProperty.Router.StaticMap {
		if contextPathGroup != nil {
			contextPathGroup.Static(mapKey, mapValue)
		} else {
			framework.GinRouter.Static(mapKey, mapValue)
		}
	}
	for mapKey, mapValue := range ginProperty.Router.StaticFileMap {
		if contextPathGroup != nil {
			contextPathGroup.StaticFile(mapKey, mapValue)
		} else {
			framework.GinRouter.StaticFile(mapKey, mapValue)
		}
	}
}

func (r *RouterMakeup) makeOtherRouter(contextPathGroup *gin.RouterGroup, ginProperty properties_gin.GinProperty) {
	if framework.ConfigContainerInst.BootstrapConfig.Sys.Profile.Mode != consts.ReleaseMode {
		if contextPathGroup != nil {
			contextPathGroup.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
		} else {
			framework.GinRouter.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
		}
	}
}

func (r *RouterMakeup) createRouterGroup(configPath, defaultPath string,
	contextPathGroup *gin.RouterGroup, handlers ...gin.HandlerFunc) *gin.RouterGroup {
	if configPath == "" {
		configPath = defaultPath
	}
	var pathGroup *gin.RouterGroup
	if contextPathGroup != nil {
		pathGroup = contextPathGroup.Group(configPath, handlers...)
	} else {
		pathGroup = framework.GinRouter.Group(configPath, handlers...)
	}
	return pathGroup
}

func (r *RouterMakeup) mergeHandlers(arrayHandles []gin.HandlerFunc, handlers ...gin.HandlerFunc) gin.HandlersChain {
	ret := gin.HandlersChain{}
	ret = append(ret, arrayHandles...)
	ret = append(ret, handlers...)
	return ret
}
